home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TPTUTR~1.ZIP / PASCAL22.TXT < prev    next >
Text File  |  1996-03-26  |  2KB  |  73 lines

  1.                        Turbo Pascal for DOS Tutorial
  2.                            by Glenn Grotzinger
  3.                              Part 22: Finale
  4.                  copyright(c) 1995-96 by Glenn Grotzinger
  5.  
  6. Here is a solution of the graphics problem from last time...
  7.  
  8. program part21; uses graph, bgivideo, crt;
  9.                    { must be in this order }
  10. var
  11.   graphicsdriver, graphicsmode: integer;
  12.   x1, x2, y1, y2: integer;
  13.  
  14. procedure errormessage(driver: string);
  15.   begin
  16.     writeln('There was an error: ', grapherrormsg(graphresult), driver);
  17.     halt(1);
  18.   end;
  19.  
  20. begin
  21.   randomize;
  22.  
  23.   if (registerbgidriver(@attdriver) < 0) then
  24.     errormessage('ATT');
  25.   if (registerbgidriver(@cgadriver) < 0) then
  26.     errormessage('CGA');
  27.   if (registerbgidriver(@egavgadriver) < 0) then
  28.     errormessage('EGA/VGA');
  29.   if (registerbgidriver(@hercdriver) < 0) then
  30.     errormessage('Herc');
  31.   if (registerbgidriver(@pc3270driver) < 0) then
  32.     errormessage('PC 3270');
  33.   detectgraph(graphicsdriver, graphicsmode);
  34.   graphicsdriver := Detect;
  35.   initgraph(graphicsdriver, graphicsmode, '');
  36.   if GraphResult <> grOk then
  37.     begin
  38.       writeln('Video error.');
  39.       halt(1);
  40.     end;
  41.  
  42.   repeat
  43.     x1 := getmaxx div 2 - 15; x2 := getmaxx div 2 + 15;
  44.     y1 := getmaxy div 2 - 15; y2 := getmaxy div 2 + 15;
  45.     { center of screen is always (getmaxx div 2, getmaxy div 2) --
  46.       look at geometric properties of a rectangle }
  47.     repeat
  48.       setcolor(random(getmaxcolor));
  49.       rectangle(x1, y1, x2, y2);
  50.       inc(x2, 1);inc(y2, 1);dec(x1, 1); dec(y1, 1);
  51.       delay(50);
  52.     until (keypressed) or (x1 <= 0);
  53.   until keypressed;
  54.  
  55.   readln;
  56.   closegraph;
  57.  
  58. end.
  59.  
  60. As you can see in this example, it's always good to have a good background
  61. in analytical geometry to be able to do graphics well.  It is good for you
  62. to find a mathematical reference and learn a few concepts of it, if you
  63. do not already know something about it.
  64.  
  65. Finale
  66. ======
  67. Ultimately, it was decided that object-oriented programming will not be
  68. covered at this time for the tutorial.  I apologize.
  69.  
  70. Note
  71. ====
  72. Be sure to read license.txt!
  73.